import { defineStore } from 'pinia'
import {
  ReqCategoryOneId,
  ReqCategoryTwoId,
  ReqCategoryThreeId,
} from '@/api/product/CategorySelector'
import type { CategoryStore } from '@/api/product/model/CategorySelectorModel'
export const useCategoryListStore = defineStore('categoryList', {
  state: (): CategoryStore => {
    return {
      category1Id: undefined,
      category2Id: undefined,
      category3Id: undefined,
      category1List: [],
      category2List: [],
      category3List: [],
    }
  },
  actions: {
    async getCategoryOneList() {
      const result = await ReqCategoryOneId()
      this.category1List = result
    },
    async getCategoryTwoList(cate1Id: number) {
      this.category1Id = cate1Id
      this.category2Id = undefined
      this.category3Id = undefined
      const result = await ReqCategoryTwoId(cate1Id)
      this.category2List = result
    },
    async getCategoryThreeList(cate2Id: number) {
      this.category2Id = cate2Id
      this.category3Id = undefined
      const result = await ReqCategoryThreeId(cate2Id)
      this.category3List = result
    },
    setCategory3Id(cate3Id: number) {
      this.category3Id = cate3Id
    },
  },
})
